package cn.itcast.itcaststore.web.servlet.manager;

import cn.itcast.itcaststore.domain.Orders;
import cn.itcast.itcaststore.serive.OrderService;
import cn.itcast.itcaststore.serive.impl.OrderServiceImpl;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


/**
 * 查看订单详情
 */
@WebServlet("/admin/findOrderById")
public class FindOrderByIdServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
       //1.获取用户类型
        String type = req.getParameter("type");
        //2.获取要查询订单的id
        String orderId = req.getParameter("id");
        //3.创建Service层对象,并根据id查询订单
        OrderService orderService = new OrderServiceImpl();
       Orders order = orderService.findOrderById(orderId);
       //4.将查询出的订单信息添加到request作用域中
        req.setAttribute("order",order);
        //5.如果用户类型不为null，则请求转发到view.jsp页面
        //否则转发到orderInfo.jsp页面
        if (type!=null){
            req.getRequestDispatcher("/admin/orders/view.jsp").forward(req,resp);
            return;
        }
        req.getRequestDispatcher("/client/orderInfo.jsp").forward(req,resp);
    }
}
